<?php
class Cms_View_Helper_SendAjaxIOForm extends Zend_View_Helper_Abstract
{
    public $view;
 
    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
    }
 
    /**
     * Validate dojo enabled form onSubmit.
     *
     * @param  string $formId
     * @return void
     */
    public function SendAjaxIOForm($formId, $url)
    {
        $this->view->headScript()->captureStart(); ?>
        function validateForm() {
        	
            var form = dijit.byId("<?php echo $formId; ?>");
            if (!form.validate()) {
                return false;
            }
           
           dojo.io.iframe.send ({
					   // The page that parses the POST request
						url: '<?php echo $url;?>',
						// Name of the Form we want to submit
						form: '<?php echo $formId; ?>',
						content: {'X-Requested-With':'XMLHttpRequest'},
						handleAs: 'text',
						// Loads this function if everything went ok
						load: function (data,ioArgs) {
								var data = dojo.fromJson(data);
			 	      	
								if(typeof sendAjaxData == 'function') {
									sendAjaxData(data);
								} 
						}
				});

        }
        
        <?php $this->view->headScript()->captureEnd();
    }
}